<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">
	
    <title>嘉定计量质量检测公共服务平台</title>
    <link href="css/css.css" rel="stylesheet" type="text/css"><!--全局-->
    <link href="css/jiliang.css" rel="stylesheet" type="text/css"><!--指定-->
     <script  src="common/js/jquery-easyui-1.2.5/jquery-1.7.1.min.js">  //引入jq
	</script> 
	<script type="text/javascript" src="common/js/json2.js"></script>
	<script type="text/javascript" src="common/js/jquery.min.js"></script>
	<script  src="common/js/init.js"> </script> 
	<script  src="common/js/basefast.js"> </script> 
      <script type="text/javascript">
	      var count=1; 
	      var add_count=1;
	      var num=0;
	      
	      window.submitDone = function(imgpath){
					$("#showsign").html("<img src='"+imgpath+"'/>");
				};

      $(document).ready( function()
   {   
    	  		var id = getQueryString("id");
    	  		if(id==null||id=="")
    	  		{
    	  			alert("您还未登录!请登录!");
    	  			window.location="index.html";
    	  		} 
    	  		var token = getQueryString("token");  
    	  		function getQueryString(name) {//取URL参数  要得到id 就传id
    			    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    			    var r = window.location.search.substr(1).match(reg);
    			    if (r != null) return unescape(r[2]); return null;
    			    }	 
    	  		
    	  	  
    	  	getJsonArrayC({"id":id,"waretype":1},"User.findListByDetails").done(function(data){ 
    	  		$("[name='UNIT_NAME']").val(data.rows[0].UNIT_NAME);	
				$("[name='SAMPLE_ADDRESS']").val(data.rows[0].SAMPLE_ADDRESS);	
				$("[name='TEL']").val(data.rows[0].TEL); 
				$("[name='LINKMAN']").val(data.rows[0].LINKMAN); 
				$("[name='FAX']").val(data.rows[0].FAX_NUMBER); 
				$("[name='POSTCODE']").val(data.rows[0].POSTCODE); 
				$("[name='INSTITUTION_CODE']").val(data.rows[0].INSTITUTION_CODE); 
	 			$.each(data.rows, function(i,item){    
			 		 	 $("#body1").before("<div class='twoitem ml15 mr15' style='overflow: hidden;' id='go"+count+"'>"
			 	     +  " <span class='font16 mb10 lh40'>  器具名称:"
			          + " <font class='ml5' name='WARE_NAME"+count+"'>"+item.WARE_NAME+"</font> "
			          + " <button class='btnkuang_or orderbtn right'  onclick='del(go"+count+")'>删除</button> "
			    +  " <button class='btn orderbtn right mr5'  onclick='edit("+count+")'>编辑</button> </span>"
			      +  "<div class='left w33' style='overflow: hidden;''>"     
			      +     " <span class='itemconname'>件数:<font class='ml5' name='NUMBER"+count+"'>"+item.NUMBER+"</font></span>" 
			  +   "   </div>"
			       +" <div class='left w33' style='overflow: hidden;''>"
			       +  "   <span class='itemconname'>修理:<font class='ml5' name='REPAIR_NUMBER"+count+"'>"+item.REPAIR_NUMBER+"</font></span>"
			     +   "</div>"
			     +  " <div class='left w33' style='overflow: hidden;'>"
			        +    "<span class='itemconname'>服务类型:<font class='ml5' name='SERVICE_TYPE"+count+"'>"+item.SERVICE_TYPE+"</font></span>"
			    +    "</div>"
			 +   "</div>");
			 		 	 num+=1;
			 		 	 count+=1; 
				 });    
			});   
    	  	
    	  	
    	  	
    	  	getJsonArrayC({"id":id },"User.getWare_type_name").done(function(data){  
	 			$.each(data.rows, function(i,item){    
			 		 		$("[name='qijuleibie']").append("<option value='"+item.ID+"'>"+item.WARE_TYPE_NAME+"</option>"); 
				 });    
			});   
    	  		getJsonArrayC({"id":id },"User.getDepartment").done(function(data){  
    	 			$.each(data.rows, function(i,item){   
    				 		if(item.DEPARTMENT_TYPE==1)
    				 			{
    				 		 		$("[name='da']").append("<option value='"+item.DEPARTMENT_TYPE+"'>"+item.DEPARTMENT+"</option>");
    				 			}
    				 		if(item.DEPARTMENT_TYPE==2)
				 			{
				 		 		$("[name='xiao']").append("<option value='"+item.DEPARTMENT_TYPE+"'>"+item.DEPARTMENT+"</option>");
				 			}
    				 });    
    			});  
    	  	
    	  		
    	  		
    	  		$("#addware").bind("click",function(){ 
    	  			if($("[name='qiju']").val().trim()==""||$("[name='jianshu']").val().trim()==""||$("[name='xiuli']").val().trim()=="")
    	  				{
    	  					alert("请检查新增上门检测计量信息是否有误(不能包含空格)!");
    	  					return;
    	  				} 
    	  			 if(!/^[0-9]*$/.test($("[name='jianshu']").val())){  
    	    		        alert("请输入正确的件数!");  
    	    		        return;
    	    		   }  
    	    		if(!/^[0-9]*$/.test($("[name='xiuli']").val())){  
    	  		        alert("请输入正确的修理件数!");  
    	  		        return;
    	  		   }  
    	  		 		   			
    	  			$("#body1").before("<div class='twoitem ml15 mr15' style='overflow: hidden;' id='goo"+add_count+"'>"
    				 +  " <span class='font16 mb10 lh40'>  器具名称:" 
     				+ " <input type='text' class='formstyle'  name='ADD_WARE_NAME"+add_count+"' value='"+ $("[name='qiju']").val( )+"' readOnly='true'>"
    				+ " <button class='btnkuang_or orderbtn right'  onclick='add_del(goo"+add_count+")'>删除</button> "
    				    +  " <button class='btn orderbtn right mr5'  onclick='add_edit("+add_count+")'>编辑</button> </span>"
    				      +  "<div class='left w33' style='overflow: hidden;''>"     
    				      +"<span class='itemconname'>件数:<input type='text' class='formstyle'  name='ADD_NUMBER"+add_count+"' value='"+ $("[name='jianshu']").val( )  +"'  readOnly='true'></span>" 
    				      +"<span class='itemconname'>器具类别:<input type='text' class='formstyle '  name='ADD_WARE_TYPE_NAME"+add_count+"' value='"+$("[name='qijuleibie']").find("option:selected").text()  +"'  readOnly='true'></span>"
    				      +"<span class='itemconname'>所属大部门:<input type='text' class='formstyle'  name='ADD_BIG_DEPARTMENT"+add_count+"' value='"+ $("[name='da']").find("option:selected").text()+"'  readOnly='true'><input type='hidden'  name='ADD_BIG_DEPARTMENT_TYPE"+add_count+"' value='"+ $("[name='da']").find("option:selected").val()+"' ></span>"
    				      +"<span class='itemconname'>所属小部门:<input type='text' class='formstyle'  name='ADD_SMALL_DEPARTMENT"+add_count+"' value='"+ $("[name='xiao']").find("option:selected").text()+"'  readOnly='true'><input type='hidden'  name='ADD_SMALL_DEPARTMENT_TYPE"+add_count+"' value='"+ $("[name='xiao']").find("option:selected").val()+"'  ></span>"
    				  +   "   </div>"
    				       +" <div class='left w33' style='overflow: hidden;''>" 
    				       +  "   <span class='itemconname'>修理:<input type='text' class='formstyle  '  name='ADD_REPAIR_NUMBER"+add_count+"' value='"+ $("[name='xiuli']").val( )  +"'  readOnly='true'></span>"
    				      +   "</div>"
    				     +  " <div class='left w33' style='overflow: hidden;'>"
    				        +    "<span class='itemconname'>服务类型:<input type='text' class='formstyle  '  name='ADD_SERVICE_TYPE"+add_count+"' value='"+ $("[name='fuwu']").find("option:selected").text()+"'  readOnly='true'></span>"
    				     +    "</div>"
    				 +   "</div>");
    	  			//var fuwu=$("[name='fuwu']").find("option:selected").text();
    	  				$("[name='qiju']").val("");
  			 			$("[name='jianshu']").val("");
  			 			$("[name='xiuli']").val("");  
    	  			add_count+=1;
    	  			
    	  		});
    	  		
    	  	$("#sub").bind("click",function(){
    	  		$("#add_count").val(add_count);
	  			$("#token").val(token);
	  			$("#yyid").val(id);
    	  		if($("[name='UNIT_NAME']").val().trim()=="")
    	  		{
    	  			alert("请填写公司名称!");
    	  			return ;
    	  		}
    	  		if($("[name='SAMPLE_ADDRESS']").val().trim()=="")
    	  		{
    	  			alert("请填写联系地址!");
    	  			return ;
    	  		}
    	  		if($("[name='TEL']").val().trim()=="")
    	  		{
    	  			alert("请填写联系方式!");
    	  			return ;
    	  		}
    	  		if($("[name='LINKMAN']").val().trim()=="")
    	  		{
    	  			alert("请填写联系人!");
    	  			return ;
    	  		}
    	  		if($("[name='INSTITUTION_CODE']").val().trim()=="")
    	  		{
    	  			alert("请填写机构代码!");
    	  			return ;
    	  		}
    	  	 
		  	if(num!=0)
		  	{
		  		alert("您还有剩余的器具信息未修改(请编辑并到下方选择器具类别以及大小部门)!");
		  		return;
		  	}
		  	if(add_count==1)
		  	{
		  		alert("您还未添加新器具!");
		  		return;
		  	}
    	  	var info = {};
   			 info.sForm=JSON.parse($("#ware_3rd").form2JSONString());
   			 Communicator.send("LoginService", "addware_3rd", info, {
   					onSuccess : function(data){ 
   						if(data.status != -1)
   						{ 
   						  		alert(data.msg);
   						}
   						else
   						{
   							alert("未知错误!请联系管理员!");
   							return;
   						}
   					},onFail:function(xmlR, status, e) {
   						//$.messager.progress('close'); 
   					}
   				});
    	  		
    	  	});//提交事件结尾
    	  			 
    	  			 
}); 
      function del(id)
      {    
    	  
    	  $( id).remove();
    	  count-=1; 
    	  num-=1;
   
      }
      function add_del(id)
      {    
    	  $( id).remove(); 
    	add_count-=1;
    	 
      }
      function edit(count)
      {    
    		
    	  	alert("请到下方编辑,确认信息完整后再新增");
    		var warename=  	$("[name='WARE_NAME"+count+"']").text();
    		var number=  	$("[name='NUMBER"+count+"']").text();
    		var repair_number=  	$("[name='REPAIR_NUMBER"+count+"']").text();
    		var service=	$("[name='SERVICE_TYPE"+count+"']").text(); 
    		 //把值移动到编辑框 
    		 $("[name='qiju']").val(warename );
  			 $("[name='jianshu']").val(number );
  			 $("[name='xiuli']").val(repair_number ) ;  
    		if(service=="检定")$("[name='fuwu']").attr("value",service);
    		if(service=="校准")$("[name='fuwu']").attr("value",service);
    		if(service=="检测")$("[name='fuwu']").attr("value",service);
    		  $("[name='fuwu']").find("option:selected").text();
    		  $("[name='qijuleibie']").find("option:selected").text();
    		  $("[name='da']").find("option:selected").text();
    		  $("[name='xiao']").find("option:selected").text(); 
    		   
    		$("#go"+count).remove(); 
    		 count-=1;
    		 num-=1;
       	  
      }
      function add_edit(add_count)
      {    
    	   
    	  	alert("请到下方编辑,确认信息完整后再新增");
    		var warename=  	$("[name='ADD_WARE_NAME"+add_count+"']").val();
    		var number=  	$("[name='ADD_NUMBER"+add_count+"']").val();
    		var repair_number=  	$("[name='ADD_REPAIR_NUMBER"+add_count+"']").val();
    		var service=	$("[name='ADD_SERVICE_TYPE"+add_count+"']").val();
    	 	
    		 //把值移动到编辑框 
    		 $("[name='qiju']").val(warename );
  			 $("[name='jianshu']").val(number );
  			 $("[name='xiuli']").val(repair_number ) ; 
  			 
    		if(service=="检定")$("[name='fuwu']").attr("value",service);
    		if(service=="校准")$("[name='fuwu']").attr("value",service);
    		if(service=="检测")$("[name='fuwu']").attr("value",service);
    		  $("[name='fuwu']").find("option:selected").text();
    		  $("[name='qijuleibie']").find("option:selected").text();
    		  $("[name='da']").find("option:selected").text();
    		  $("[name='xiao']").find("option:selected").text();
    		
    		  
    		$("#goo"+add_count).remove(); 
    		add_count-=1;
    		alert("addcount目前为:"+add_count);
      }
      
      </script> 
</head>
<body>
<form id="ware_3rd" method="post">
<section class="infogroup">
    <div class="group-title">单位信息</div>
    <div class="twoitem ml15 mr15" style="overflow: hidden;">
        <div class="left oneitemcon">
            <span class="itemconname">单位名称:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="UNIT_NAME"/></span>
        </div>
        <div class="right oneitemcon">
            <span class="itemconname">联系地址:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="SAMPLE_ADDRESS"/></span>
        </div>
    </div>
    <div class="twoitem ml15 mr15" style="overflow: hidden;">
        <div class="left oneitemcon">
            <span class="itemconname">联系电话:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="TEL"/></span>
        </div>
        <div class="right oneitemcon">
            <span class="itemconname">联系人:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="LINKMAN"/></span>
        </div>
    </div>
    <div class="twoitem ml15 mr15" style="overflow: hidden;">
        <div class="left oneitemcon">
            <span class="itemconname">传真号:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="FAX"/></span>
        </div>
        <div class="right oneitemcon">
            <span class="itemconname">邮编:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="POSTCODE"/></span>
        </div>
    </div>
    <div class="twoitem ml15 mr15" style="overflow: hidden;">
        <div class="left oneitemcon">
            <span class="itemconname">机构代码:</span>
            <span class="itemconsubtitle mt3"><input class="numberformstyle w90" type="text" placeholder="" name="INSTITUTION_CODE"/></span>
        </div>
    </div>
</section>


<section class="infogroup mt15"> 
    <div class="group-title"  id="body1">上门检测计量</div>  
    <input type="hidden" id="add_count" value="1" name="add_count">
    <input type="hidden" id="token" value="0" name="token">
    <input type="hidden" id="yyid" value="0" name="yyid">
</section>


</form>

<section class="infogroup">
    <div class="group-title"  >新增上门检测计量</div>
    <div class="inputarea">
        <span class="inputnamebig">器具名称</span>
        <span class="inputformbig"> 
            <input class="formstyle w100" type="text" placeholder="请输入器具名称" name="qiju"  />
        </span>
    </div>
    <div class="inputarea">
        <span class="inputnamebig">件数</span>
        <span class="inputformbig">   <input class="formstyle w100" type="text" placeholder="请输入件数" name="jianshu" />
        </span>
    </div>
    <div class="inputarea">
        <span class="inputnamebig">修理</span>
        <span class="inputformbig"> 
        <input class="formstyle w100" type="text" placeholder="请输入修理件数" name="xiuli" />
        </span>
    </div>
    <div class="inputarea">
        <span class="inputnamebig">服务类型</span>
        <span class="inputformbig">
            <i class="iconfont wipe">&#xe6db;</i>
            <select class="crm_select" name="fuwu">
                <option>检定</option>
                <option>校准</option>
                <option>检测</option>
            </select>
        </span>
    </div>
    <div class="inputarea">
        <span class="inputnamebig">器具类别</span>
        <span class="inputformbig">
            <i class="iconfont wipe">&#xe6db;</i>
            <select class="crm_select" name="qijuleibie" >
                 
            </select>
        </span>
    </div>
    <div class="inputarea">
        <span class="inputnamebig">所属大部门</span>
        <span class="inputformbig">
            <i class="iconfont wipe">&#xe6db;</i>
            <select class="crm_select" name="da">
               
            </select>
        </span>
    </div>
    <div class="inputarea">
        <span class="inputnamebig">所属小部门</span>
        <span class="inputformbig">
            <i class="iconfont wipe">&#xe6db;</i>
            <select class="crm_select" name="xiao">
                
            </select>
        </span>
    </div>
</section>
<section class="infogroup2">
    <div class="photoitem lh30 tc font16 blue" id="addware">+添加新器具</div>
</section> 

<section class="infogroup2">
    <div class="photoitem lh30 tc font16 blue" id="showsign"></div>
</section> 
 
<section class="p15 p15r mt15 mb10" style="overflow: hidden">
    <button class="btn bottomone2btn left" onclick="javascript:delegate.addSign();">客户签字</button>
    <button class="btn bottomone2btn right" id="sub">完成订单</button>
</section>

</body>
</html>